import os

class Configuration(object):
    """ 
    This class is the Python EasyAccept configuration class. It's used for handling
    the Python EA default configuration and to get dinamic configuration data, that depends
    of the operational system.
    
    @author: Gustavo Pereira
    """
        
    FILE_SEPARATOR = os.sep
    WHITE_LINE_CODE = os.linesep
    ERROR_CODE = "FAILURE"
    SUCCESS_CODE = "PASSED"
    COMMENT_CODE = "#"
    ECHO_CODE = "echo"
    PARENT_DIR = os.pardir
    TEST_SCRIPTS_LOCATION = FILE_SEPARATOR + "resources"+ FILE_SEPARATOR + "scripts_for_test"
    ACCEPTANCE_TEST_SCRIPTS_LOCATION = FILE_SEPARATOR + "resources"+ FILE_SEPARATOR + "scripts_for_acceptance_test"
    ICONS_LOCATION = FILE_SEPARATOR + "icons"
        
    if os.name == "nt":
        PATH_TO_BROWSE = os.getenv("USERPROFILE")
    else: 
        PATH_TO_BROWSE = os.getenv("HOME")    
        
    if os.name == "nt":
        import _winreg
        explorer = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software" + FILE_SEPARATOR + "PythonEasyAccept")
        INSTALL_DIR = _winreg.QueryValue(explorer, "Software" + FILE_SEPARATOR + "PythonEasyAccept")
        _winreg.CloseKey(explorer)
#        INSTALL_DIR = os.getenv("PROGRAMFILES") + FILE_SEPARATOR +  "PythonEasyAccept"
    else:
        INSTALL_DIR = os.getenv("HOME") + FILE_SEPARATOR +  "PythonEasyAccept"

        
    BACKGROUND_COLOUR = '#E6E6FA'
    
    __configSingleInstance = None
 
    def __init__(self):
        self.root = os.path.abspath(self.PARENT_DIR + self.FILE_SEPARATOR + self.PARENT_DIR)
    
    def getInstance():
        if(Configuration.__configSingleInstance == None):
            Configuration.__configSingleInstance = Configuration()
            return Configuration.__configSingleInstance
        
        return Configuration.__configSingleInstance
    
    getInstance = staticmethod(getInstance)    
        
    def setInstallDir(self, installDir):
        self.INSTALL_DIR = installDir
        
    def getProjectRoot(self):
        """
        This method returns the project root path
        @return: the project root path
        """   
        return self.root
    
